<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>创造对象</title>
</head>
<body>
  <script>
    //1、new+object
    var person=new Object();
    person.name="zzc";
    person.fn=function(){
      console.log("person的name："+this.name);
    }
    person.fn();

    //2、字面量创建对象
    var person1={
      name:"zzc",
      fn:function(){
        console.log("person1的name："+this.name)
      }
    }
    person1.fn();

    //3、工厂模式的创建
    function person2(name,sex){
      var obj=new Object();
      obj.name=name;
      obj.sex=sex;
      return obj;
    }
    var createObj=person2("zzc","男")
    console.log(createObj instanceof Object)
    //工厂模式解决了多次实例化对象的问题，但没有解决识别对象的问题

    //4、构造函数创建对象
    function person3(name,sex){
      this.name=name;
      this.sex=sex;
      this.fn=function(){
        console.log("person3的姓名："+this.name+";person3的性别："+this.sex)
      }
    }
    var createObjs=new person3("pxl","女");
    createObjs.fn();
  </script>
</body>
</html>